﻿namespace UnityEditor
{
    using NUnit.Framework;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using UnityEngine;

    [CanEditMultipleObjects, CustomEditor(typeof(TextureImporter))]
    internal class TextureImporterInspector : AssetImporterInspector
    {
        private static readonly TextureImporterFormat[] kFormatsWithCompressionSettings = new TextureImporterFormat[] { TextureImporterFormat.PVRTC_RGB2, TextureImporterFormat.PVRTC_RGB4, TextureImporterFormat.PVRTC_RGBA2, TextureImporterFormat.PVRTC_RGBA4, TextureImporterFormat.ATC_RGB4, TextureImporterFormat.ATC_RGBA8, TextureImporterFormat.ETC_RGB4, TextureImporterFormat.ATF_RGB_JPG, TextureImporterFormat.ATF_RGBA_JPG };
        private static readonly string[] kMaxTextureSizeStrings = new string[] { "32", "64", "128", "256", "512", "1024", "2048", "4096" };
        private static readonly int[] kMaxTextureSizeValues = new int[] { 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000 };
        private static readonly int[] kNormalFormatsValueAndroid = new int[] { 12, 0x1f, 0x21, 0x24, 13, 4 };
        private static readonly int[] kNormalFormatsValueFlash = new int[] { 0x27, 4 };
        private static readonly int[] kNormalFormatsValueiPhone = new int[] { 0x1f, 0x21, 13, 4 };
        private static readonly int[] kNormalFormatsValueWeb = new int[] { 12, 2, 5 };
        private static readonly int[] kNormalFormatValueWii = new int[] { 0x18, 0x19, 0x1a, 0x1b };
        private static readonly int[] kTextureFormatsValueAndroid = new int[] { 10, 12, 0x22, 30, 0x1f, 0x20, 0x21, 0x23, 0x24, 7, 3, 1, 13, 4 };
        private static readonly int[] kTextureFormatsValueFlash = new int[] { 40, 0x27, 3, 4 };
        private static readonly int[] kTextureFormatsValueGLESEmu = new int[] { 0x22, 30, 0x1f, 0x20, 0x21, 7, 3, 1, 13, 5 };
        private static readonly int[] kTextureFormatsValueiPhone = new int[] { 30, 0x1f, 0x20, 0x21, 7, 3, 1, 13, 4 };
        private static readonly int[] kTextureFormatsValueWeb = new int[] { 10, 12, 7, 3, 1, 2, 5 };
        private static readonly int[] kTextureFormatsValueWii = new int[] { 20, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b };
        private readonly AnimValueManager m_Anims = new AnimValueManager();
        private SerializedProperty m_Aniso;
        private SerializedProperty m_BorderMipMap;
        private SerializedProperty m_ConvertToNormalMap;
        private SerializedProperty m_EnableMipMap;
        private SerializedProperty m_FadeOut;
        private SerializedProperty m_FilterMode;
        private SerializedProperty m_GenerateCubemap;
        private SerializedProperty m_GenerateMipsInLinearSpace;
        private SerializedProperty m_GrayscaleToAlpha;
        private SerializedProperty m_HeightScale;
        private SerializedProperty m_IsReadable;
        private SerializedProperty m_Lightmap;
        private SerializedProperty m_LinearTexture;
        private SerializedProperty m_MipMapFadeDistanceEnd;
        private SerializedProperty m_MipMapFadeDistanceStart;
        private SerializedProperty m_MipMapMode;
        private SerializedProperty m_NormalMap;
        private SerializedProperty m_NormalMapFilter;
        private SerializedProperty m_NPOTScale;
        [SerializeField]
        protected List<PlatformSetting> m_PlatformSettings;
        private SerializedProperty m_SeamlessCubemap;
        private readonly AnimBool m_ShowBumpGenerationSettings = new AnimBool();
        private readonly AnimBool m_ShowCookieCubeMapSettings = new AnimBool();
        private readonly int[] m_TextureFormatValues;
        private SerializedProperty m_TextureType;
        private readonly int[] m_TextureTypeValues = new int[] { 0, 1, 2, 7, 3, 4, 6, 5 };
        private SerializedProperty m_WrapMode;
        private static string[] s_NormalFormatStringsAll;
        private static string[] s_NormalFormatStringsAndroid;
        private static string[] s_NormalFormatStringsFlash;
        private static string[] s_NormalFormatStringsiPhone;
        private static string[] s_NormalFormatStringsWeb;
        private static int[] s_NormalFormatsValueAll;
        private static Styles s_Styles;
        private static string[] s_TextureFormatStringsAll;
        private static string[] s_TextureFormatStringsAndroid;
        private static string[] s_TextureFormatStringsFlash;
        private static string[] s_TextureFormatStringsGLESEmu;
        private static string[] s_TextureFormatStringsiPhone;
        private static string[] s_TextureFormatStringsWeb;
        private static string[] s_TextureFormatStringsWii;
        private static int[] s_TextureFormatsValueAll;

        public TextureImporterInspector()
        {
            int[] numArray1 = new int[3];
            numArray1[1] = 1;
            numArray1[2] = 2;
            this.m_TextureFormatValues = numArray1;
        }

        private void AdvancedGUI()
        {
            TextureImporter target = base.target as TextureImporter;
            if (target != null)
            {
                int height = 0;
                int width = 0;
                target.GetWidthAndHeight(ref width, ref height);
                bool disabled = IsPowerOfTwo(height) && IsPowerOfTwo(width);
                EditorGUI.BeginDisabledGroup(disabled);
                this.EnumPopup(this.m_NPOTScale, typeof(TextureImporterNPOTScale), s_Styles.npot);
                EditorGUI.EndDisabledGroup();
                EditorGUI.BeginDisabledGroup(!disabled && (this.m_NPOTScale.intValue == 0));
                this.EnumPopup(this.m_GenerateCubemap, typeof(TextureImporterGenerateCubemap), s_Styles.generateCubemap);
                EditorGUI.EndDisabledGroup();
                this.ToggleLabelBefore(this.m_IsReadable, s_Styles.readWrite);
                AdvancedTextureType normalMap = AdvancedTextureType.Default;
                if (this.m_NormalMap.intValue > 0)
                {
                    normalMap = AdvancedTextureType.NormalMap;
                }
                else if (this.m_Lightmap.intValue > 0)
                {
                    normalMap = AdvancedTextureType.LightMap;
                }
                EditorGUI.BeginChangeCheck();
                string[] displayedOptions = new string[] { "Default", "Normal Map", "Lightmap" };
                normalMap = (AdvancedTextureType) EditorGUILayout.Popup("Import Type", (int) normalMap, displayedOptions, new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    switch (normalMap)
                    {
                        case AdvancedTextureType.Default:
                            this.m_NormalMap.intValue = 0;
                            this.m_Lightmap.intValue = 0;
                            this.m_ConvertToNormalMap.intValue = 0;
                            break;

                        case AdvancedTextureType.NormalMap:
                            this.m_NormalMap.intValue = 1;
                            this.m_Lightmap.intValue = 0;
                            this.m_LinearTexture.intValue = 1;
                            break;

                        case AdvancedTextureType.LightMap:
                            this.m_NormalMap.intValue = 0;
                            this.m_Lightmap.intValue = 1;
                            this.m_ConvertToNormalMap.intValue = 0;
                            this.m_LinearTexture.intValue = 1;
                            break;
                    }
                }
                EditorGUI.indentLevel++;
                switch (normalMap)
                {
                    case AdvancedTextureType.NormalMap:
                        EditorGUI.BeginChangeCheck();
                        this.BumpGUI();
                        if (EditorGUI.EndChangeCheck())
                        {
                            this.SyncPlatformSettings();
                        }
                        break;

                    case AdvancedTextureType.Default:
                        this.ToggleLabelBefore(this.m_GrayscaleToAlpha, s_Styles.generateAlphaFromGrayscale);
                        this.ToggleLabelBefore(this.m_LinearTexture, s_Styles.linearTexture);
                        break;
                }
                EditorGUI.indentLevel--;
                this.BeginToggleGroup(this.m_EnableMipMap, s_Styles.generateMipMaps);
                EditorGUI.indentLevel++;
                this.ToggleLabelBefore(this.m_GenerateMipsInLinearSpace, s_Styles.mipMapsInLinearSpace);
                this.ToggleLabelBefore(this.m_BorderMipMap, s_Styles.borderMipMaps);
                EditorGUILayout.Popup(this.m_MipMapMode, s_Styles.mipMapFilterOptions, s_Styles.mipMapFilter, new GUILayoutOption[0]);
                this.ToggleLabelAfter(this.m_FadeOut, s_Styles.mipmapFadeOutToggle);
                if (this.m_FadeOut.intValue > 0)
                {
                    EditorGUI.indentLevel++;
                    EditorGUI.BeginChangeCheck();
                    float intValue = this.m_MipMapFadeDistanceStart.intValue;
                    float maxValue = this.m_MipMapFadeDistanceEnd.intValue;
                    EditorGUILayout.MinMaxSlider(s_Styles.mipmapFadeOut, ref intValue, ref maxValue, 0f, 10f, new GUILayoutOption[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.m_MipMapFadeDistanceStart.intValue = Mathf.RoundToInt(intValue);
                        this.m_MipMapFadeDistanceEnd.intValue = Mathf.RoundToInt(maxValue);
                    }
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.EndToggleGroup();
            }
        }

        internal override void Apply()
        {
            base.Apply();
            this.SyncPlatformSettings();
            foreach (PlatformSetting setting in this.m_PlatformSettings)
            {
                setting.Apply();
            }
        }

        private void ApplySettingsToTexture()
        {
            foreach (AssetImporter importer in base.targets)
            {
                Texture tex = AssetDatabase.LoadMainAssetAtPath(importer.assetPath) as Texture;
                if (this.m_Aniso.intValue != -1)
                {
                    TextureUtil.SetAnisoLevelNoDirty(tex, this.m_Aniso.intValue);
                }
                if (this.m_FilterMode.intValue != -1)
                {
                    TextureUtil.SetFilterModeNoDirty(tex, (UnityEngine.FilterMode) this.m_FilterMode.intValue);
                }
                if (this.m_WrapMode.intValue != -1)
                {
                    TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode) this.m_WrapMode.intValue);
                }
            }
            SceneView.RepaintAll();
        }

        private void BeginToggleGroup(SerializedProperty property, GUIContent label)
        {
            EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            int num = !EditorGUILayout.BeginToggleGroup(label, property.intValue > 0) ? 0 : 1;
            if (EditorGUI.EndChangeCheck())
            {
                property.intValue = num;
            }
            EditorGUI.showMixedValue = false;
        }

        public virtual void BuildTargetList()
        {
            List<BuildPlayerWindow.BuildPlatform> validPlatforms = BuildPlayerWindow.GetValidPlatforms();
            this.m_PlatformSettings = new List<PlatformSetting>();
            this.m_PlatformSettings.Add(new PlatformSetting(string.Empty, BuildTarget.StandaloneWindows, this));
            foreach (BuildPlayerWindow.BuildPlatform platform in validPlatforms)
            {
                this.m_PlatformSettings.Add(new PlatformSetting(platform.name, platform.DefaultTarget, this));
            }
        }

        private static string[] BuildTextureStrings(int[] texFormatValues)
        {
            string[] strArray = new string[texFormatValues.Length];
            for (int i = 0; i < texFormatValues.Length; i++)
            {
                int num2 = texFormatValues[i];
                int num3 = num2;
                switch ((num3 + 3))
                {
                    case 0:
                        strArray[i] = "Automatic Truecolor";
                        break;

                    case 1:
                        strArray[i] = "Automatic 16 bits";
                        break;

                    case 2:
                        strArray[i] = "Automatic Compressed";
                        break;

                    default:
                        strArray[i] = " " + TextureUtil.GetTextureFormatString((TextureFormat) num2);
                        break;
                }
            }
            return strArray;
        }

        private void BumpGUI()
        {
            this.ToggleLabelAfter(this.m_ConvertToNormalMap, s_Styles.generateFromBump);
            this.m_ShowBumpGenerationSettings.target = this.m_ConvertToNormalMap.intValue > 0;
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowBumpGenerationSettings.faded))
            {
                EditorGUILayout.Slider(this.m_HeightScale, 0f, 0.3f, s_Styles.bumpiness, new GUILayoutOption[0]);
                EditorGUILayout.Popup(this.m_NormalMapFilter, s_Styles.bumpFilteringOptions, s_Styles.bumpFiltering, new GUILayoutOption[0]);
            }
            EditorGUILayout.EndFadeGroup();
        }

        private void CacheSerializedProperties()
        {
            this.m_TextureType = base.serializedObject.FindProperty("m_TextureType");
            this.m_GrayscaleToAlpha = base.serializedObject.FindProperty("m_GrayScaleToAlpha");
            this.m_ConvertToNormalMap = base.serializedObject.FindProperty("m_ConvertToNormalMap");
            this.m_NormalMap = base.serializedObject.FindProperty("m_ExternalNormalMap");
            this.m_HeightScale = base.serializedObject.FindProperty("m_HeightScale");
            this.m_NormalMapFilter = base.serializedObject.FindProperty("m_NormalMapFilter");
            this.m_GenerateCubemap = base.serializedObject.FindProperty("m_GenerateCubemap");
            this.m_SeamlessCubemap = base.serializedObject.FindProperty("m_SeamlessCubemap");
            this.m_BorderMipMap = base.serializedObject.FindProperty("m_BorderMipMap");
            this.m_NPOTScale = base.serializedObject.FindProperty("m_NPOTScale");
            this.m_IsReadable = base.serializedObject.FindProperty("m_IsReadable");
            this.m_LinearTexture = base.serializedObject.FindProperty("m_LinearTexture");
            this.m_EnableMipMap = base.serializedObject.FindProperty("m_EnableMipMap");
            this.m_MipMapMode = base.serializedObject.FindProperty("m_MipMapMode");
            this.m_GenerateMipsInLinearSpace = base.serializedObject.FindProperty("correctGamma");
            this.m_FadeOut = base.serializedObject.FindProperty("m_FadeOut");
            this.m_MipMapFadeDistanceStart = base.serializedObject.FindProperty("m_MipMapFadeDistanceStart");
            this.m_MipMapFadeDistanceEnd = base.serializedObject.FindProperty("m_MipMapFadeDistanceEnd");
            this.m_Lightmap = base.serializedObject.FindProperty("m_Lightmap");
            this.m_Aniso = base.serializedObject.FindProperty("m_TextureSettings.m_Aniso");
            this.m_FilterMode = base.serializedObject.FindProperty("m_TextureSettings.m_FilterMode");
            this.m_WrapMode = base.serializedObject.FindProperty("m_TextureSettings.m_WrapMode");
        }

        private void CookieGUI()
        {
            CookieMode spot;
            EditorGUI.BeginChangeCheck();
            if (this.m_BorderMipMap.intValue > 0)
            {
                spot = CookieMode.Spot;
            }
            else if (this.m_GenerateCubemap.intValue != 0)
            {
                spot = CookieMode.Point;
            }
            else
            {
                spot = CookieMode.Directional;
            }
            spot = (CookieMode) EditorGUILayout.Popup(s_Styles.cookieType, (int) spot, s_Styles.cookieOptions, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                this.SetCookieMode(spot);
            }
            this.m_ShowCookieCubeMapSettings.target = spot == CookieMode.Point;
            if (EditorGUILayout.BeginFadeGroup(this.m_ShowCookieCubeMapSettings.faded))
            {
                this.ReflectionMappingGUI();
            }
            EditorGUILayout.EndFadeGroup();
            this.ToggleLabelAfter(this.m_GrayscaleToAlpha, s_Styles.generateAlphaFromGrayscale);
        }

        private int EditCompressionQuality(BuildTarget target, int compression)
        {
            if ((target == BuildTarget.iPhone) || (target == BuildTarget.Android))
            {
                int selectedIndex = 1;
                if (compression == 0)
                {
                    selectedIndex = 0;
                }
                else if (compression == 100)
                {
                    selectedIndex = 2;
                }
                switch (EditorGUILayout.Popup(s_Styles.compressionQuality, selectedIndex, s_Styles.mobileCompressionQualityOptions, new GUILayoutOption[0]))
                {
                    case 0:
                        return 0;

                    case 1:
                        return 50;

                    case 2:
                        return 100;
                }
                return 50;
            }
            if (target == BuildTarget.FlashPlayer)
            {
                return EditorGUILayout.IntSlider(s_Styles.compressionQuality, compression, 0, 100, new GUILayoutOption[0]);
            }
            return compression;
        }

        private void EnumPopup(SerializedProperty property, System.Type type, GUIContent label)
        {
            EditorGUILayout.IntPopup(property, EditorGUIUtility.TempContent(Enum.GetNames(type)), Enum.GetValues(type) as int[], label, new GUILayoutOption[0]);
        }

        private TextureImporterSettings GetSerializedPropertySettings()
        {
            return this.GetSerializedPropertySettings(new TextureImporterSettings());
        }

        private TextureImporterSettings GetSerializedPropertySettings(TextureImporterSettings settings)
        {
            if (!this.m_GrayscaleToAlpha.hasMultipleDifferentValues)
            {
                settings.grayscaleToAlpha = this.m_GrayscaleToAlpha.intValue > 0;
            }
            if (!this.m_ConvertToNormalMap.hasMultipleDifferentValues)
            {
                settings.convertToNormalMap = this.m_ConvertToNormalMap.intValue > 0;
            }
            if (!this.m_NormalMap.hasMultipleDifferentValues)
            {
                settings.normalMap = this.m_NormalMap.intValue > 0;
            }
            if (!this.m_HeightScale.hasMultipleDifferentValues)
            {
                settings.heightmapScale = this.m_HeightScale.floatValue;
            }
            if (!this.m_NormalMapFilter.hasMultipleDifferentValues)
            {
                settings.normalMapFilter = (TextureImporterNormalFilter) this.m_NormalMapFilter.intValue;
            }
            if (!this.m_GenerateCubemap.hasMultipleDifferentValues)
            {
                settings.generateCubemap = (TextureImporterGenerateCubemap) this.m_GenerateCubemap.intValue;
            }
            if (!this.m_SeamlessCubemap.hasMultipleDifferentValues)
            {
                settings.seamlessCubemap = this.m_SeamlessCubemap.intValue > 0;
            }
            if (!this.m_BorderMipMap.hasMultipleDifferentValues)
            {
                settings.borderMipmap = this.m_BorderMipMap.intValue > 0;
            }
            if (!this.m_NPOTScale.hasMultipleDifferentValues)
            {
                settings.npotScale = (TextureImporterNPOTScale) this.m_NPOTScale.intValue;
            }
            if (!this.m_IsReadable.hasMultipleDifferentValues)
            {
                settings.readable = this.m_IsReadable.intValue > 0;
            }
            if (!this.m_LinearTexture.hasMultipleDifferentValues)
            {
                settings.linearTexture = this.m_LinearTexture.intValue > 0;
            }
            if (!this.m_EnableMipMap.hasMultipleDifferentValues)
            {
                settings.mipmapEnabled = this.m_EnableMipMap.intValue > 0;
            }
            if (!this.m_GenerateMipsInLinearSpace.hasMultipleDifferentValues)
            {
                settings.generateMipsInLinearSpace = this.m_GenerateMipsInLinearSpace.intValue > 0;
            }
            if (!this.m_MipMapMode.hasMultipleDifferentValues)
            {
                settings.mipmapFilter = (TextureImporterMipFilter) this.m_MipMapMode.intValue;
            }
            if (!this.m_FadeOut.hasMultipleDifferentValues)
            {
                settings.fadeOut = this.m_FadeOut.intValue > 0;
            }
            if (!this.m_MipMapFadeDistanceStart.hasMultipleDifferentValues)
            {
                settings.mipmapFadeDistanceStart = this.m_MipMapFadeDistanceStart.intValue;
            }
            if (!this.m_MipMapFadeDistanceEnd.hasMultipleDifferentValues)
            {
                settings.mipmapFadeDistanceEnd = this.m_MipMapFadeDistanceEnd.intValue;
            }
            if (!this.m_Lightmap.hasMultipleDifferentValues)
            {
                settings.lightmap = this.m_Lightmap.intValue > 0;
            }
            if (!this.m_WrapMode.hasMultipleDifferentValues)
            {
                settings.wrapMode = (TextureWrapMode) this.m_WrapMode.intValue;
            }
            if (!this.m_FilterMode.hasMultipleDifferentValues)
            {
                settings.filterMode = (UnityEngine.FilterMode) this.m_FilterMode.intValue;
            }
            if (!this.m_Aniso.hasMultipleDifferentValues)
            {
                settings.aniso = this.m_Aniso.intValue;
            }
            return settings;
        }

        internal override bool HasModified()
        {
            if (base.HasModified())
            {
                return true;
            }
            foreach (PlatformSetting setting in this.m_PlatformSettings)
            {
                if (setting.HasChanged())
                {
                    return true;
                }
            }
            return false;
        }

        private void ImageGUI()
        {
            this.ToggleLabelAfter(this.m_GrayscaleToAlpha, s_Styles.generateAlphaFromGrayscale);
        }

        private static bool IsPowerOfTwo(int f)
        {
            return ((f & (f - 1)) == 0);
        }

        private static TextureImporterFormat MakeTextureFormatHaveAlpha(TextureImporterFormat format)
        {
            switch (format)
            {
                case TextureImporterFormat.RGB16:
                    return TextureImporterFormat.ARGB16;

                case TextureImporterFormat.DXT1:
                    return TextureImporterFormat.DXT5;

                case TextureImporterFormat.PVRTC_RGB2:
                    return TextureImporterFormat.PVRTC_RGBA2;

                case TextureImporterFormat.PVRTC_RGB4:
                    return TextureImporterFormat.PVRTC_RGBA4;

                case TextureImporterFormat.RGB24:
                    return TextureImporterFormat.ARGB32;
            }
            return format;
        }

        public virtual void OnEnable()
        {
            this.CacheSerializedProperties();
            this.m_Anims.Add(this.m_ShowBumpGenerationSettings);
            this.m_Anims.Add(this.m_ShowCookieCubeMapSettings);
            this.m_ShowCookieCubeMapSettings.value = (this.textureType == TextureImporterType.Cookie) && (this.m_GenerateCubemap.intValue != 0);
            this.m_ShowBumpGenerationSettings.value = this.m_ConvertToNormalMap.intValue > 0;
        }

        public override void OnInspectorGUI()
        {
            if (this.m_Anims.callback == null)
            {
                this.m_Anims.callback = new AnimValueManager.Callback(this.Repaint);
            }
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.textureTypeHasMultipleDifferentValues;
            int num = EditorGUILayout.IntPopup(s_Styles.textureType, (int) this.textureType, s_Styles.textureTypeOptions, this.m_TextureTypeValues, new GUILayoutOption[0]);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                this.m_TextureType.intValue = num;
                TextureImporterSettings serializedPropertySettings = this.GetSerializedPropertySettings();
                serializedPropertySettings.ApplyTextureType(this.textureType, true);
                this.SetSerializedPropertySettings(serializedPropertySettings);
                this.SyncPlatformSettings();
                this.ApplySettingsToTexture();
            }
            if (!this.textureTypeHasMultipleDifferentValues)
            {
                switch (this.textureType)
                {
                    case TextureImporterType.Image:
                        this.ImageGUI();
                        break;

                    case TextureImporterType.Bump:
                        this.BumpGUI();
                        break;

                    case TextureImporterType.Reflection:
                        this.ReflectionGUI();
                        break;

                    case TextureImporterType.Cookie:
                        this.CookieGUI();
                        break;

                    case TextureImporterType.Advanced:
                        this.AdvancedGUI();
                        break;
                }
            }
            EditorGUILayout.Space();
            this.PreviewableGUI();
            this.SizeAndFormatGUI();
            base.ApplyRevertGUI();
        }

        private void PreviewableGUI()
        {
            EditorGUI.BeginChangeCheck();
            if (((this.textureType != TextureImporterType.GUI) && (this.textureType != TextureImporterType.Reflection)) && ((this.textureType != TextureImporterType.Cookie) && (this.textureType != TextureImporterType.Lightmap)))
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = this.m_WrapMode.hasMultipleDifferentValues;
                TextureWrapMode selected = (TextureWrapMode) this.m_WrapMode.intValue;
                if (selected == ~TextureWrapMode.Repeat)
                {
                    selected = TextureWrapMode.Repeat;
                }
                selected = (TextureWrapMode) EditorGUILayout.EnumPopup(EditorGUIUtility.TempContent("Wrap Mode"), selected, new GUILayoutOption[0]);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    this.m_WrapMode.intValue = (int) selected;
                }
            }
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = this.m_FilterMode.hasMultipleDifferentValues;
            UnityEngine.FilterMode intValue = (UnityEngine.FilterMode) this.m_FilterMode.intValue;
            if (intValue == ~UnityEngine.FilterMode.Point)
            {
                if (((this.m_FadeOut.intValue > 0) || (this.m_ConvertToNormalMap.intValue > 0)) || (this.m_NormalMap.intValue > 0))
                {
                    intValue = UnityEngine.FilterMode.Trilinear;
                }
                else
                {
                    intValue = UnityEngine.FilterMode.Bilinear;
                }
            }
            intValue = (UnityEngine.FilterMode) EditorGUILayout.EnumPopup(EditorGUIUtility.TempContent("Filter Mode"), intValue, new GUILayoutOption[0]);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                this.m_FilterMode.intValue = (int) intValue;
            }
            if ((intValue != UnityEngine.FilterMode.Point) && ((this.m_EnableMipMap.intValue > 0) || (this.textureType == TextureImporterType.Advanced)))
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = this.m_Aniso.hasMultipleDifferentValues;
                int num = this.m_Aniso.intValue;
                if (num == -1)
                {
                    num = 1;
                }
                num = EditorGUILayout.IntSlider("Aniso Level", num, 0, 9, new GUILayoutOption[0]);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    this.m_Aniso.intValue = num;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.ApplySettingsToTexture();
            }
        }

        private void ReflectionGUI()
        {
            this.ReflectionMappingGUI();
        }

        private void ReflectionMappingGUI()
        {
            EditorGUI.showMixedValue = this.m_GenerateCubemap.hasMultipleDifferentValues || this.m_SeamlessCubemap.hasMultipleDifferentValues;
            EditorGUI.BeginChangeCheck();
            int num = EditorGUILayout.Popup(s_Styles.refMap, this.m_GenerateCubemap.intValue - 1, s_Styles.refMapOptions, new GUILayoutOption[0]) + 1;
            if (EditorGUI.EndChangeCheck())
            {
                this.m_GenerateCubemap.intValue = num;
            }
            this.ToggleLabelAfter(this.m_SeamlessCubemap, s_Styles.seamlessCubemap);
            EditorGUI.showMixedValue = false;
        }

        internal override void ResetValues()
        {
            base.ResetValues();
            this.CacheSerializedProperties();
            this.BuildTargetList();
            Assert.IsFalse(this.HasModified(), "TextureImporter settings are marked as modified after calling Reset.");
            this.ApplySettingsToTexture();
        }

        private void SetCookieMode(CookieMode cm)
        {
            switch (cm)
            {
                case CookieMode.Spot:
                    this.m_BorderMipMap.intValue = 1;
                    this.m_WrapMode.intValue = 1;
                    this.m_GenerateCubemap.intValue = 0;
                    break;

                case CookieMode.Directional:
                    this.m_BorderMipMap.intValue = 0;
                    this.m_WrapMode.intValue = 0;
                    this.m_GenerateCubemap.intValue = 0;
                    break;

                case CookieMode.Point:
                    this.m_BorderMipMap.intValue = 0;
                    this.m_WrapMode.intValue = 1;
                    this.m_GenerateCubemap.intValue = 3;
                    break;
            }
        }

        private void SetSerializedPropertySettings(TextureImporterSettings settings)
        {
            this.m_GrayscaleToAlpha.intValue = !settings.grayscaleToAlpha ? 0 : 1;
            this.m_ConvertToNormalMap.intValue = !settings.convertToNormalMap ? 0 : 1;
            this.m_NormalMap.intValue = !settings.normalMap ? 0 : 1;
            this.m_HeightScale.floatValue = settings.heightmapScale;
            this.m_NormalMapFilter.intValue = (int) settings.normalMapFilter;
            this.m_GenerateCubemap.intValue = (int) settings.generateCubemap;
            this.m_SeamlessCubemap.intValue = !settings.seamlessCubemap ? 0 : 1;
            this.m_BorderMipMap.intValue = !settings.borderMipmap ? 0 : 1;
            this.m_NPOTScale.intValue = (int) settings.npotScale;
            this.m_IsReadable.intValue = !settings.readable ? 0 : 1;
            this.m_EnableMipMap.intValue = !settings.mipmapEnabled ? 0 : 1;
            this.m_LinearTexture.intValue = !settings.linearTexture ? 0 : 1;
            this.m_MipMapMode.intValue = (int) settings.mipmapFilter;
            this.m_GenerateMipsInLinearSpace.intValue = !settings.generateMipsInLinearSpace ? 0 : 1;
            this.m_FadeOut.intValue = !settings.fadeOut ? 0 : 1;
            this.m_MipMapFadeDistanceStart.intValue = settings.mipmapFadeDistanceStart;
            this.m_MipMapFadeDistanceEnd.intValue = settings.mipmapFadeDistanceEnd;
            this.m_Lightmap.intValue = !settings.lightmap ? 0 : 1;
            this.m_WrapMode.intValue = (int) settings.wrapMode;
            this.m_FilterMode.intValue = (int) settings.filterMode;
            this.m_Aniso.intValue = settings.aniso;
        }

        protected void SizeAndFormatGUI()
        {
            BuildPlayerWindow.BuildPlatform[] platforms = BuildPlayerWindow.GetValidPlatforms().ToArray();
            GUILayout.Space(10f);
            int num = EditorGUILayout.BeginPlatformGrouping(platforms, s_Styles.defaultPlatform);
            PlatformSetting setting = this.m_PlatformSettings[num + 1];
            if (!setting.isDefault)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = setting.overriddenIsDifferent;
                bool overridden = GUILayout.Toggle(setting.overridden, "Override for " + setting.name, new GUILayoutOption[0]);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    setting.SetOverriddenForAll(overridden);
                    this.SyncPlatformSettings();
                }
            }
            bool disabled = !setting.isDefault && !setting.allAreOverridden;
            EditorGUI.BeginDisabledGroup(disabled);
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = setting.overriddenIsDifferent || setting.maxTextureSizeIsDifferent;
            int maxTextureSize = EditorGUILayout.IntPopup(s_Styles.maxSize.text, setting.maxTextureSize, kMaxTextureSizeStrings, kMaxTextureSizeValues, new GUILayoutOption[0]);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                setting.SetMaxTextureSizeForAll(maxTextureSize);
                this.SyncPlatformSettings();
            }
            int[] second = null;
            string[] strArray = null;
            bool flag3 = false;
            int selectedValue = 0;
            bool flag4 = false;
            int num4 = 0;
            bool flag5 = false;
            for (int i = 0; i < base.targets.Length; i++)
            {
                TextureImporter importer = base.targets[i] as TextureImporter;
                TextureImporterType tType = !this.textureTypeHasMultipleDifferentValues ? this.textureType : importer.textureType;
                TextureImporterSettings settings = setting.GetSettings(importer);
                int num6 = (int) setting.textureFormats[i];
                int num7 = num6;
                if (!setting.isDefault && (num6 < 0))
                {
                    num7 = (int) TextureImporter.SimpleToFullTextureFormat2((TextureImporterFormat) num7, tType, settings, importer.DoesSourceTextureHaveAlpha(), importer.DoesSourceTextureHaveColor(), setting.m_Target);
                }
                if (settings.normalMap)
                {
                    num7 = (int) MakeTextureFormatHaveAlpha((TextureImporterFormat) num7);
                }
                TextureImporterType type2 = tType;
                if (type2 != TextureImporterType.Cookie)
                {
                    if (type2 == TextureImporterType.Advanced)
                    {
                        goto Label_01FE;
                    }
                    goto Label_049B;
                }
                int[] first = new int[1];
                string[] textureFormatOptions = new string[] { "8 Bit Alpha" };
                num6 = 0;
                goto Label_04CB;
            Label_01FE:
                num6 = num7;
                if (!settings.normalMap)
                {
                    if (s_TextureFormatStringsAll == null)
                    {
                        s_TextureFormatStringsAll = BuildTextureStrings(TextureFormatsValueAll);
                    }
                    if (s_TextureFormatStringsWii == null)
                    {
                        s_TextureFormatStringsWii = BuildTextureStrings(kTextureFormatsValueWii);
                    }
                    if (s_TextureFormatStringsGLESEmu == null)
                    {
                        s_TextureFormatStringsGLESEmu = BuildTextureStrings(kTextureFormatsValueGLESEmu);
                    }
                    if (s_TextureFormatStringsiPhone == null)
                    {
                        s_TextureFormatStringsiPhone = BuildTextureStrings(kTextureFormatsValueiPhone);
                    }
                    if (s_TextureFormatStringsAndroid == null)
                    {
                        s_TextureFormatStringsAndroid = BuildTextureStrings(kTextureFormatsValueAndroid);
                    }
                    if (s_TextureFormatStringsFlash == null)
                    {
                        s_TextureFormatStringsFlash = BuildTextureStrings(kTextureFormatsValueFlash);
                    }
                    if (s_TextureFormatStringsWeb == null)
                    {
                        s_TextureFormatStringsWeb = BuildTextureStrings(kTextureFormatsValueWeb);
                    }
                    if (setting.isDefault)
                    {
                        first = TextureFormatsValueAll;
                        textureFormatOptions = s_TextureFormatStringsAll;
                    }
                    else if (setting.m_Target == BuildTarget.Wii)
                    {
                        first = kTextureFormatsValueWii;
                        textureFormatOptions = s_TextureFormatStringsWii;
                    }
                    else if (setting.m_Target == BuildTarget.StandaloneGLESEmu)
                    {
                        first = kTextureFormatsValueGLESEmu;
                        textureFormatOptions = s_TextureFormatStringsGLESEmu;
                    }
                    else if (setting.m_Target == BuildTarget.iPhone)
                    {
                        first = kTextureFormatsValueiPhone;
                        textureFormatOptions = s_TextureFormatStringsiPhone;
                    }
                    else if (setting.m_Target == BuildTarget.Android)
                    {
                        first = kTextureFormatsValueAndroid;
                        textureFormatOptions = s_TextureFormatStringsAndroid;
                    }
                    else if (setting.m_Target == BuildTarget.FlashPlayer)
                    {
                        first = kTextureFormatsValueFlash;
                        textureFormatOptions = s_TextureFormatStringsFlash;
                    }
                    else
                    {
                        first = kTextureFormatsValueWeb;
                        textureFormatOptions = s_TextureFormatStringsWeb;
                    }
                }
                else
                {
                    if (s_NormalFormatStringsAll == null)
                    {
                        s_NormalFormatStringsAll = BuildTextureStrings(NormalFormatsValueAll);
                    }
                    if (s_NormalFormatStringsiPhone == null)
                    {
                        s_NormalFormatStringsiPhone = BuildTextureStrings(kNormalFormatsValueiPhone);
                    }
                    if (s_NormalFormatStringsAndroid == null)
                    {
                        s_NormalFormatStringsAndroid = BuildTextureStrings(kNormalFormatsValueAndroid);
                    }
                    if (s_NormalFormatStringsFlash == null)
                    {
                        s_NormalFormatStringsFlash = BuildTextureStrings(kNormalFormatsValueFlash);
                    }
                    if (s_NormalFormatStringsWeb == null)
                    {
                        s_NormalFormatStringsWeb = BuildTextureStrings(kNormalFormatsValueWeb);
                    }
                    if (setting.isDefault)
                    {
                        first = NormalFormatsValueAll;
                        textureFormatOptions = s_NormalFormatStringsAll;
                    }
                    else if (setting.m_Target == BuildTarget.iPhone)
                    {
                        first = kNormalFormatsValueiPhone;
                        textureFormatOptions = s_NormalFormatStringsiPhone;
                    }
                    else if (setting.m_Target == BuildTarget.Android)
                    {
                        first = kNormalFormatsValueAndroid;
                        textureFormatOptions = s_NormalFormatStringsAndroid;
                    }
                    else if (setting.m_Target == BuildTarget.FlashPlayer)
                    {
                        first = kNormalFormatsValueFlash;
                        textureFormatOptions = s_NormalFormatStringsFlash;
                    }
                    else
                    {
                        first = kNormalFormatsValueWeb;
                        textureFormatOptions = s_NormalFormatStringsWeb;
                    }
                }
                goto Label_04CB;
            Label_049B:
                first = this.m_TextureFormatValues;
                textureFormatOptions = s_Styles.textureFormatOptions;
                if (num6 >= 0)
                {
                    num6 = (int) TextureImporter.FullToSimpleTextureFormat((TextureImporterFormat) num6);
                }
                num6 = -1 - num6;
            Label_04CB:
                if (i == 0)
                {
                    second = first;
                    strArray = textureFormatOptions;
                    selectedValue = num6;
                    num4 = num7;
                }
                else
                {
                    if (num6 != selectedValue)
                    {
                        flag4 = true;
                    }
                    if (num7 != num4)
                    {
                        flag5 = true;
                    }
                    if (!first.SequenceEqual<int>(second) || !textureFormatOptions.SequenceEqual<string>(strArray))
                    {
                        flag3 = true;
                        break;
                    }
                }
            }
            EditorGUI.BeginDisabledGroup(flag3 || (strArray.Length == 1));
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = flag3 || flag4;
            selectedValue = EditorGUILayout.IntPopup(s_Styles.textureFormat, selectedValue, EditorGUIUtility.TempContent(strArray), second, new GUILayoutOption[0]);
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                if (this.textureType != TextureImporterType.Advanced)
                {
                    selectedValue = -1 - selectedValue;
                }
                setting.SetTextureFormatForAll((TextureImporterFormat) selectedValue);
                this.SyncPlatformSettings();
            }
            EditorGUI.EndDisabledGroup();
            if (!flag5 && ArrayUtility.Contains<TextureImporterFormat>(kFormatsWithCompressionSettings, (TextureImporterFormat) num4))
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = setting.overriddenIsDifferent || setting.compressionQualityIsDifferent;
                int quality = this.EditCompressionQuality(setting.m_Target, setting.compressionQuality);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    setting.SetCompressionQualityForAll(quality);
                    this.SyncPlatformSettings();
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndPlatformGrouping();
        }

        private void SyncPlatformSettings()
        {
            foreach (PlatformSetting setting in this.m_PlatformSettings)
            {
                setting.Sync();
            }
        }

        private void ToggleLabelAfter(SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
            int num = !EditorGUILayout.Toggle(label, property.intValue > 0, new GUILayoutOption[0]) ? 0 : 1;
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                property.intValue = num;
            }
        }

        private void ToggleLabelBefore(SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
            int num = !EditorGUILayout.Toggle(label, property.intValue > 0, new GUILayoutOption[0]) ? 0 : 1;
            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                property.intValue = num;
            }
        }

        private static int[] NormalFormatsValueAll
        {
            get
            {
                bool flag = false;
                bool flag2 = false;
                foreach (BuildPlayerWindow.BuildPlatform platform in BuildPlayerWindow.GetValidPlatforms().ToArray())
                {
                    switch (platform.DefaultTarget)
                    {
                        case BuildTarget.iPhone:
                            flag = true;
                            break;

                        case BuildTarget.Android:
                            flag = true;
                            flag2 = true;
                            break;

                        case BuildTarget.StandaloneGLESEmu:
                            flag = true;
                            break;
                    }
                }
                List<int> list = new List<int>();
                int[] collection = new int[] { -1, 12 };
                list.AddRange(collection);
                if (flag)
                {
                    int[] numArray2 = new int[] { 0x1f, 0x21 };
                    list.AddRange(numArray2);
                }
                if (flag2)
                {
                    int[] numArray3 = new int[] { 0x24 };
                    list.AddRange(numArray3);
                }
                list.AddRange(new int[] { -2, 2, 13, -3, 4 });
                s_NormalFormatsValueAll = list.ToArray();
                return s_NormalFormatsValueAll;
            }
        }

        internal override bool showImportedObject
        {
            get
            {
                return false;
            }
        }

        private static int[] TextureFormatsValueAll
        {
            get
            {
                if (s_TextureFormatsValueAll == null)
                {
                    bool flag = false;
                    bool flag2 = false;
                    bool flag3 = false;
                    foreach (BuildPlayerWindow.BuildPlatform platform in BuildPlayerWindow.GetValidPlatforms().ToArray())
                    {
                        switch (platform.DefaultTarget)
                        {
                            case BuildTarget.iPhone:
                                flag2 = true;
                                break;

                            case BuildTarget.Android:
                                flag2 = true;
                                flag = true;
                                flag3 = true;
                                break;

                            case BuildTarget.StandaloneGLESEmu:
                                flag2 = true;
                                flag = true;
                                break;
                        }
                    }
                    List<int> list = new List<int>();
                    int[] collection = new int[] { -1, 10, 12 };
                    list.AddRange(collection);
                    if (flag)
                    {
                        list.Add(0x22);
                    }
                    if (flag2)
                    {
                        list.AddRange(new int[] { 30, 0x1f, 0x20, 0x21 });
                    }
                    if (flag3)
                    {
                        int[] numArray2 = new int[] { 0x23, 0x24 };
                        list.AddRange(numArray2);
                    }
                    list.AddRange(new int[] { -2, 7, 2, 13, -3, 3, 1, 5, 4 });
                    s_TextureFormatsValueAll = list.ToArray();
                }
                return s_TextureFormatsValueAll;
            }
        }

        private TextureImporterType textureType
        {
            get
            {
                if (this.textureTypeHasMultipleDifferentValues)
                {
                    return ~TextureImporterType.Image;
                }
                if (this.m_TextureType.intValue < 0)
                {
                    return (base.target as TextureImporter).textureType;
                }
                return (TextureImporterType) this.m_TextureType.intValue;
            }
        }

        private bool textureTypeHasMultipleDifferentValues
        {
            get
            {
                if (this.m_TextureType.hasMultipleDifferentValues)
                {
                    return true;
                }
                if (this.m_TextureType.intValue < 0)
                {
                    TextureImporterType textureType = (base.target as TextureImporter).textureType;
                    foreach (UnityEngine.Object obj2 in base.targets)
                    {
                        if ((obj2 as TextureImporter).textureType != textureType)
                        {
                            return true;
                        }
                    }
                }
                return false;
            }
        }

        private enum AdvancedTextureType
        {
            Default,
            NormalMap,
            LightMap
        }

        private enum CookieMode
        {
            Spot,
            Directional,
            Point
        }

        [Serializable]
        protected class PlatformSetting
        {
            [CompilerGenerated]
            private static Func<UnityEngine.Object, TextureImporter> <>f__am$cacheD;
            [SerializeField]
            private int m_CompressionQuality;
            [SerializeField]
            private bool m_CompressionQualityIsDifferent;
            [SerializeField]
            private bool m_HasChanged;
            [SerializeField]
            private TextureImporter[] m_Importers;
            [SerializeField]
            private TextureImporterInspector m_Inspector;
            [SerializeField]
            private int m_MaxTextureSize;
            [SerializeField]
            private bool m_MaxTextureSizeIsDifferent;
            [SerializeField]
            private bool m_Overridden;
            [SerializeField]
            private bool m_OverriddenIsDifferent;
            [SerializeField]
            public BuildTarget m_Target;
            [SerializeField]
            private TextureImporterFormat[] m_TextureFormatArray;
            [SerializeField]
            private bool m_TextureFormatIsDifferent;
            [SerializeField]
            public string name;

            public PlatformSetting(string name, BuildTarget target, TextureImporterInspector inspector)
            {
                this.name = name;
                this.m_Target = target;
                this.m_Inspector = inspector;
                this.m_Overridden = false;
                if (<>f__am$cacheD == null)
                {
                    <>f__am$cacheD = new Func<UnityEngine.Object, TextureImporter>(TextureImporterInspector.PlatformSetting.<PlatformSetting>m__61);
                }
                this.m_Importers = Enumerable.Select<UnityEngine.Object, TextureImporter>(inspector.targets, <>f__am$cacheD).ToArray<TextureImporter>();
                this.m_TextureFormatArray = new TextureImporterFormat[this.importers.Length];
                for (int i = 0; i < this.importers.Length; i++)
                {
                    TextureImporterFormat textureFormat;
                    int maxTextureSize;
                    int compressionQuality;
                    bool flag;
                    TextureImporter importer = this.importers[i];
                    if (!this.isDefault)
                    {
                        flag = importer.GetPlatformTextureSettings(name, out maxTextureSize, out textureFormat, out compressionQuality);
                    }
                    else
                    {
                        flag = true;
                        maxTextureSize = importer.maxTextureSize;
                        textureFormat = importer.textureFormat;
                        compressionQuality = importer.compressionQuality;
                    }
                    this.m_TextureFormatArray[i] = textureFormat;
                    if (i == 0)
                    {
                        this.m_Overridden = flag;
                        this.m_MaxTextureSize = maxTextureSize;
                        this.m_CompressionQuality = compressionQuality;
                    }
                    else
                    {
                        if (flag != this.m_Overridden)
                        {
                            this.m_OverriddenIsDifferent = true;
                        }
                        if (maxTextureSize != this.m_MaxTextureSize)
                        {
                            this.m_MaxTextureSizeIsDifferent = true;
                        }
                        if (compressionQuality != this.m_CompressionQuality)
                        {
                            this.m_CompressionQualityIsDifferent = true;
                        }
                        if (textureFormat != this.m_TextureFormatArray[0])
                        {
                            this.m_TextureFormatIsDifferent = true;
                        }
                    }
                }
                this.Sync();
            }

            [CompilerGenerated]
            private static TextureImporter <PlatformSetting>m__61(UnityEngine.Object x)
            {
                return (x as TextureImporter);
            }

            public void Apply()
            {
                for (int i = 0; i < this.importers.Length; i++)
                {
                    int maxTextureSize;
                    TextureImporter importer = this.importers[i];
                    int compressionQuality = -1;
                    bool overridden = false;
                    if (this.isDefault)
                    {
                        maxTextureSize = importer.maxTextureSize;
                    }
                    else
                    {
                        TextureImporterFormat format;
                        overridden = importer.GetPlatformTextureSettings(this.name, out maxTextureSize, out format, out compressionQuality);
                    }
                    if (!overridden)
                    {
                        maxTextureSize = importer.maxTextureSize;
                    }
                    if (!this.m_MaxTextureSizeIsDifferent)
                    {
                        maxTextureSize = this.m_MaxTextureSize;
                    }
                    if (!this.m_CompressionQualityIsDifferent)
                    {
                        compressionQuality = this.m_CompressionQuality;
                    }
                    if (!this.isDefault)
                    {
                        if (!this.m_OverriddenIsDifferent)
                        {
                            overridden = this.m_Overridden;
                        }
                        if (overridden)
                        {
                            importer.SetPlatformTextureSettings(this.name, maxTextureSize, this.m_TextureFormatArray[i], compressionQuality);
                        }
                        else
                        {
                            importer.ClearPlatformTextureSettings(this.name);
                        }
                    }
                    else
                    {
                        importer.maxTextureSize = maxTextureSize;
                        importer.textureFormat = this.m_TextureFormatArray[i];
                    }
                }
            }

            private bool GetOverridden(TextureImporter importer)
            {
                int num;
                TextureImporterFormat format;
                if (!this.m_OverriddenIsDifferent)
                {
                    return this.m_Overridden;
                }
                return importer.GetPlatformTextureSettings(this.name, out num, out format);
            }

            public TextureImporterSettings GetSettings(TextureImporter importer)
            {
                TextureImporterSettings dest = new TextureImporterSettings();
                importer.ReadTextureSettings(dest);
                this.m_Inspector.GetSerializedPropertySettings(dest);
                return dest;
            }

            public virtual bool HasChanged()
            {
                return this.m_HasChanged;
            }

            public void SetCompressionQualityForAll(int quality)
            {
                Assert.IsTrue(this.allAreOverridden, "Attempting to set texture compression quality for all platforms even though settings are not overwritten for all platforms.");
                this.m_CompressionQuality = quality;
                this.m_CompressionQualityIsDifferent = false;
                this.m_HasChanged = true;
            }

            public void SetMaxTextureSizeForAll(int maxTextureSize)
            {
                Assert.IsTrue(this.allAreOverridden, "Attempting to set max texture size for all platforms even though settings are not overwritten for all platforms.");
                this.m_MaxTextureSize = maxTextureSize;
                this.m_MaxTextureSizeIsDifferent = false;
                this.m_HasChanged = true;
            }

            public void SetOverriddenForAll(bool overridden)
            {
                this.m_Overridden = overridden;
                this.m_OverriddenIsDifferent = false;
                this.m_HasChanged = true;
            }

            public void SetTextureFormatForAll(TextureImporterFormat format)
            {
                Assert.IsTrue(this.allAreOverridden, "Attempting to set texture format for all platforms even though settings are not overwritten for all platforms.");
                for (int i = 0; i < this.m_TextureFormatArray.Length; i++)
                {
                    this.m_TextureFormatArray[i] = format;
                }
                this.m_TextureFormatIsDifferent = false;
                this.m_HasChanged = true;
            }

            public bool SupportsFormat(TextureImporterFormat format, TextureImporter importer)
            {
                int[] numArray;
                TextureImporterSettings settings = this.GetSettings(importer);
                BuildTarget target = this.m_Target;
                switch (target)
                {
                    case BuildTarget.Wii:
                        numArray = !settings.normalMap ? TextureImporterInspector.kTextureFormatsValueWii : TextureImporterInspector.kNormalFormatValueWii;
                        break;

                    case BuildTarget.iPhone:
                        numArray = !settings.normalMap ? TextureImporterInspector.kTextureFormatsValueiPhone : TextureImporterInspector.kNormalFormatsValueiPhone;
                        break;

                    case BuildTarget.Android:
                        numArray = !settings.normalMap ? TextureImporterInspector.kTextureFormatsValueAndroid : TextureImporterInspector.kNormalFormatsValueAndroid;
                        break;

                    case BuildTarget.StandaloneGLESEmu:
                        numArray = !settings.normalMap ? TextureImporterInspector.kTextureFormatsValueGLESEmu : TextureImporterInspector.kNormalFormatsValueWeb;
                        break;

                    default:
                        if (target == BuildTarget.FlashPlayer)
                        {
                            numArray = !settings.normalMap ? TextureImporterInspector.kTextureFormatsValueFlash : TextureImporterInspector.kNormalFormatsValueFlash;
                        }
                        else
                        {
                            numArray = !settings.normalMap ? TextureImporterInspector.kTextureFormatsValueWeb : TextureImporterInspector.kNormalFormatsValueWeb;
                        }
                        break;
                }
                return numArray.Contains((int) format);
            }

            public void Sync()
            {
                if (!this.isDefault && (!this.m_Overridden || this.m_OverriddenIsDifferent))
                {
                    TextureImporterInspector.PlatformSetting setting = this.m_Inspector.m_PlatformSettings[0];
                    this.m_MaxTextureSize = setting.m_MaxTextureSize;
                    this.m_MaxTextureSizeIsDifferent = setting.m_MaxTextureSizeIsDifferent;
                    this.m_TextureFormatArray = (TextureImporterFormat[]) setting.m_TextureFormatArray.Clone();
                    this.m_TextureFormatIsDifferent = setting.m_TextureFormatIsDifferent;
                    this.m_CompressionQuality = setting.m_CompressionQuality;
                    this.m_CompressionQualityIsDifferent = setting.m_CompressionQualityIsDifferent;
                }
                TextureImporterType textureType = this.m_Inspector.textureType;
                for (int i = 0; i < this.importers.Length; i++)
                {
                    TextureImporter importer = this.importers[i];
                    TextureImporterSettings settings = this.GetSettings(importer);
                    if (textureType == TextureImporterType.Advanced)
                    {
                        if (this.isDefault)
                        {
                            continue;
                        }
                        if (!this.SupportsFormat(this.m_TextureFormatArray[i], importer))
                        {
                            this.m_TextureFormatArray[i] = TextureImporter.FullToSimpleTextureFormat(this.m_TextureFormatArray[i]);
                        }
                        if (this.m_TextureFormatArray[i] < ~TextureImporterFormat.AutomaticCompressed)
                        {
                            this.m_TextureFormatArray[i] = TextureImporter.SimpleToFullTextureFormat2(this.m_TextureFormatArray[i], textureType, settings, importer.DoesSourceTextureHaveAlpha(), importer.DoesSourceTextureHaveColor(), this.m_Target);
                        }
                    }
                    else if (this.m_TextureFormatArray[i] >= ~TextureImporterFormat.AutomaticCompressed)
                    {
                        this.m_TextureFormatArray[i] = TextureImporter.FullToSimpleTextureFormat(this.m_TextureFormatArray[i]);
                    }
                    if (settings.normalMap)
                    {
                        this.m_TextureFormatArray[i] = TextureImporterInspector.MakeTextureFormatHaveAlpha(this.m_TextureFormatArray[i]);
                    }
                }
                this.m_TextureFormatIsDifferent = false;
                foreach (TextureImporterFormat format in this.m_TextureFormatArray)
                {
                    if (format != this.m_TextureFormatArray[0])
                    {
                        this.m_TextureFormatIsDifferent = true;
                    }
                }
            }

            public bool allAreOverridden
            {
                get
                {
                    return (this.isDefault || (this.m_Overridden && !this.m_OverriddenIsDifferent));
                }
            }

            public int compressionQuality
            {
                get
                {
                    return this.m_CompressionQuality;
                }
            }

            public bool compressionQualityIsDifferent
            {
                get
                {
                    return this.m_CompressionQualityIsDifferent;
                }
            }

            public TextureImporter[] importers
            {
                get
                {
                    return this.m_Importers;
                }
            }

            public bool isDefault
            {
                get
                {
                    return (this.name == string.Empty);
                }
            }

            public int maxTextureSize
            {
                get
                {
                    return this.m_MaxTextureSize;
                }
            }

            public bool maxTextureSizeIsDifferent
            {
                get
                {
                    return this.m_MaxTextureSizeIsDifferent;
                }
            }

            public bool overridden
            {
                get
                {
                    return this.m_Overridden;
                }
            }

            public bool overriddenIsDifferent
            {
                get
                {
                    return this.m_OverriddenIsDifferent;
                }
            }

            public bool textureFormatIsDifferent
            {
                get
                {
                    return this.m_TextureFormatIsDifferent;
                }
            }

            public TextureImporterFormat[] textureFormats
            {
                get
                {
                    return this.m_TextureFormatArray;
                }
            }
        }

        private class Styles
        {
            public readonly GUIContent borderMipMaps = EditorGUIUtility.TextContent("TextureImporter.BorderMipMaps");
            public readonly GUIContent bumpFiltering = EditorGUIUtility.TextContent("TextureImporter.BumpFiltering");
            public readonly GUIContent[] bumpFilteringOptions = new GUIContent[] { EditorGUIUtility.TextContent("TextureImporter.BumpFiltering.Sharp"), EditorGUIUtility.TextContent("TextureImporter.BumpFiltering.Smooth") };
            public readonly GUIContent bumpiness = EditorGUIUtility.TextContent("TextureImporter.Bumpiness");
            public readonly GUIContent compressionQuality = EditorGUIUtility.TextContent("TextureImporter.CompressionQuality");
            public readonly GUIContent[] cookieOptions = new GUIContent[] { EditorGUIUtility.TextContent("TextureImporter.Cookie.Spot"), EditorGUIUtility.TextContent("TextureImporter.Cookie.Directional"), EditorGUIUtility.TextContent("TextureImporter.Cookie.Point") };
            public readonly GUIContent cookieType = EditorGUIUtility.TextContent("TextureImporter.Cookie");
            public readonly GUIContent defaultPlatform = EditorGUIUtility.TextContent("TextureImporter.Platforms.Default");
            public readonly GUIContent generateAlphaFromGrayscale = EditorGUIUtility.TextContent("TextureImporter.GenerateAlphaFromGrayscale");
            public readonly GUIContent generateBumpmap = EditorGUIUtility.TextContent("TextureImporter.GenerateBumpmap");
            public readonly GUIContent generateCubemap = EditorGUIUtility.TextContent("TextureImporter.GenerateCubemap");
            public readonly GUIContent generateFromBump = EditorGUIUtility.TextContent("TextureImporter.GenerateFromBump");
            public readonly GUIContent generateMipMaps = EditorGUIUtility.TextContent("TextureImporter.GenerateMipMaps");
            public readonly GUIContent lightmap = EditorGUIUtility.TextContent("TextureImporter.Lightmap");
            public readonly GUIContent linearTexture = EditorGUIUtility.TextContent("TextureImporter.LinearTexture");
            public readonly GUIContent maxSize = EditorGUIUtility.TextContent("TextureImporter.MaxSize");
            public readonly GUIContent mipmapFadeOut = EditorGUIUtility.TextContent("TextureImporter.MipmapFade");
            public readonly GUIContent mipmapFadeOutToggle = EditorGUIUtility.TextContent("TextureImporter.MipmapFadeToggle");
            public readonly GUIContent mipMapFilter = EditorGUIUtility.TextContent("TextureImporter.MipMapFilter");
            public readonly GUIContent[] mipMapFilterOptions = new GUIContent[] { EditorGUIUtility.TextContent("TextureImporter.MipMapFilterOptions.Box"), EditorGUIUtility.TextContent("TextureImporter.MipMapFilterOptions.Kaiser") };
            public readonly GUIContent mipMapsInLinearSpace = EditorGUIUtility.TextContent("TextureImporter.MipMapsInLinearSpace");
            public readonly GUIContent[] mobileCompressionQualityOptions = new GUIContent[] { EditorGUIUtility.TextContent("TextureImporter.CompressionQualityOptions.Fast"), EditorGUIUtility.TextContent("TextureImporter.CompressionQualityOptions.Normal"), EditorGUIUtility.TextContent("TextureImporter.CompressionQualityOptions.Best") };
            public readonly GUIContent normalmap = EditorGUIUtility.TextContent("TextureImporter.NormalMap");
            public readonly GUIContent npot = EditorGUIUtility.TextContent("TextureImporter.Npot");
            public readonly GUIContent readWrite = EditorGUIUtility.TextContent("TextureImporter.ReadWrite");
            public readonly GUIContent refMap = EditorGUIUtility.TextContent("TextureImporter.RefMap");
            public readonly GUIContent[] refMapOptions = new GUIContent[] { EditorGUIUtility.TextContent("TextureImporter.RefMap.Sphere"), EditorGUIUtility.TextContent("TextureImporter.RefMap.Cylindrical"), EditorGUIUtility.TextContent("TextureImporter.RefMap.SimpleSphere"), EditorGUIUtility.TextContent("TextureImporter.RefMap.NiceSphere"), EditorGUIUtility.TextContent("TextureImporter.RefMap.FullCubemap") };
            public readonly GUIContent seamlessCubemap = EditorGUIUtility.TextContent("TextureImporter.SeamlessCubemap");
            public readonly GUIContent textureFormat = EditorGUIUtility.TextContent("TextureImporter.TextureFormat");
            public readonly string[] textureFormatOptions = new string[] { EditorGUIUtility.TextContent("TextureImporter.TextureFormat.Compressed").text, EditorGUIUtility.TextContent("TextureImporter.TextureFormat.16 bit").text, EditorGUIUtility.TextContent("TextureImporter.TextureFormat.Truecolor").text };
            public readonly GUIContent textureType = EditorGUIUtility.TextContent("TextureImporter.TextureType");
            public readonly GUIContent[] textureTypeOptions = new GUIContent[] { EditorGUIUtility.TextContent("TextureImporter.TextureType.Image"), EditorGUIUtility.TextContent("TextureImporter.TextureType.Normalmap"), EditorGUIUtility.TextContent("TextureImporter.TextureType.GUI"), EditorGUIUtility.TextContent("TextureImporter.TextureType.Cursor"), EditorGUIUtility.TextContent("TextureImporter.TextureType.Reflection"), EditorGUIUtility.TextContent("TextureImporter.TextureType.Cookie"), EditorGUIUtility.TextContent("TextureImporter.TextureType.Lightmap"), EditorGUIUtility.TextContent("TextureImporter.TextureType.Advanced") };
        }
    }
}

